package relu.fbs.xt;

import java.util.Map;

import relu.fbs.BadDataException;
import relu.fbs.xt.FBSFarmData.FBSFarmDatum;

public class FBSDataReader {

	public static boolean addSectionCTotal(FBSFarmData parent,FBSPost2000DataPoint ident,double value) throws BadDataException {
		switch (ident.row){
		case 410:
			// ignore it
			return false;
		case 901:
//			Cereals (excluding maize) TAC second tranche based on 1999 registrations.
			// Ignore
			return true;
		case 905:
			//Set-aside TAC second tranche based on 1999 registrations.
			// Ignore
			return true;
		case 904:
			//Proteins TAC second tranche based on 1999 registrations.
			//Ignore
			return true;
		case 903:
			//Linseed TAC second tranche based on 1999 registrations.
			// Ignore
			return true;
		case 906:
			//Additional voluntary set-aside TAC second tranche based on 1999 registrations
			// Ignore
			return true;
		case 902:
//			Oilseed rape TAC second tranche based on 1999 registrations.
			// Ignore
			return true;
		case 423:
//			Fodder maize TAC second tranche based on 1999 registrations
			// Ignore
			return true;
		case 907:
			//Grain maize TAC second tranche based on 1999 registrations
			// Ignore
			return true;
		case 316:
			// UNknown
			return true;
		case 299:
			switch(ident.col){
			case 50:
				// Ignore
				return true;
			case 41:
				if ( ident.ctype==10){					
					parent.putCheckedFarmData(FBSFarmDatum.TOTALMAINEO, value);
				}
				return true; // return true regardless
			case 21:
				if ( ident.ctype==10){					
					parent.putCheckedFarmData(FBSFarmDatum.TOTALMAINAREA, value);
				}
				return true; // return true regardless
			case 28:
				if ( ident.ctype==10){					
					parent.putCheckedFarmData(FBSFarmDatum.TOTALMAINCV, value);
				}
				return true; // return true regardless
			case 30:
				if ( ident.ctype==10){					
					parent.putCheckedFarmData(FBSFarmDatum.TOTALMAINREV, value);
				}
				return true; // return true regardless
			case 32:
				if ( ident.ctype==10){					
					parent.putFarmData(FBSFarmDatum.TOTALMAINFARMCONS, value);
				}
				return true; // return true regardless
			case 34:
				if ( ident.ctype==10){					
					parent.putFarmData(FBSFarmDatum.TOTALMAINFARMFEED, value);
				}
				return true; // return true regardless
			case 40:
				if ( ident.ctype==10){					
					parent.putCheckedFarmData(FBSFarmDatum.TOTALMAINAREAPAY, value);
				}
				return true; // return true regardless
			case 39:
				if ( ident.ctype==10){					
					parent.putCheckedFarmData(FBSFarmDatum.TOTALMAINAREAPAYMENTDUE, value);
				}
				return true; // return true regardless
			case 26:
				if ( ident.ctype==9 || ident.ctype==10){
					return true;
				}
				break;
			case 42:
				if ( ident.ctype==9 || ident.ctype==10){
					return true;
				}
				break;
			case 36:
				if ( ident.ctype==9 || ident.ctype==10){
					return true;
				}
				break;
			default:
				throw new BadDataException("Unknown column "+ident.col+" for row 299");
			}
		case 418:
			switch(ident.col){
			case 21:
				if ( ident.ctype==10){					
					parent.putFarmData(FBSFarmDatum.TOTALFORAGEAREA, value);
				}
				return true; // return true regardless
			case 40:
				// ignore
				return false;
			case 41:
				// ignore
				return false;
			case 50:
				return true;
			default:	
				throw new BadDataException("Unknown column "+ident.col+" for row 418");
			}
		case 422:
			switch(ident.col){
			case 21:
				if ( ident.ctype==10){
					parent.putFarmData(FBSFarmDatum.SETASIDEAREA,value);
				}
				return true;
			case 22:
					// Ignore the data 
				return true;
			case 50:
				// Missing set aside data .. flag bad farm
				parent.flagBadFarm();
				// Ignore
				return true;
			case 51:
				// Revenue code?? 
				// Ignore
				return true;
			case 39:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.AREAELIGIBLESETASIDE,value);
				}
				return true;
			case 40:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.SETASIDEPAYMENT,value);
				}
				return true;
			case 41:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.SETASIDEEO,value);
				}
				return true;
			default:
				throw new BadDataException("Unknown column "+ident.col+" for row 422");
		}
			
		case 424:
			switch(ident.col){
			case 21:
				if ( ident.ctype==10){
					parent.putFarmData(FBSFarmDatum.UCAREA,value);
				}
				return true;
			case 40:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.UCPAYMENT,value);
				}
				return true;
			case 41:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.UCEO,value);
				}
				return true;
			default:
				throw new BadDataException("Unknown column "+ident.col+" for row 424");
		}
		case 408:
			switch(ident.col){
			case 21:
				if ( ident.ctype==10){
					parent.putFarmData(FBSFarmDatum.SYRSETASIDEAREA,value);
				}
				return true;
			case 40:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.SYRSETASIDEPAYMENT,value);
				}
				return true;
			case 41:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.SYRSETASIDEEO,value);
				}
				return true;
			default:
				throw new BadDataException("Unknown column "+ident.col+" for row 408");
		}
		case 421:
			switch(ident.col){
			case 21:
				if ( ident.ctype==10){
					parent.putFarmData(FBSFarmDatum.NRSETASIDEAREA,value);
				}
				return true;
			case 40:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.NRSETASIDEPAYMENT,value);
				}
				return true;
			case 41:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.NRSETASIDEEO,value);
				}
				return true;
			default:
				throw new BadDataException("Unknown column "+ident.col+" for row 408");
		}
		case 414:
			switch(ident.col){
			case 21:
				if ( ident.ctype==10){
					parent.putFarmData(FBSFarmDatum.SYSETASIDEAREA,value);
				}
				return true;
			case 40:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.SYSETASIDEPAYMENT,value);
				}
				return true;
			case 41:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.SYSETASIDEEO,value);
				}
				return true;
			default:
				throw new BadDataException("Unknown column "+ident.col+" for row 414");
		}
		case 419:
			switch(ident.col){
			case 21:
				if ( ident.ctype==10){
					parent.putFarmData(FBSFarmDatum.CSETASIDEAREA,value);
				}
				return true;
			case 40:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.CSETASIDEPAYMENT,value);
				}
				return true;
			case 41:
				if ( ident.ctype==10){
					parent.putCheckedFarmData(FBSFarmDatum.CSETASIDEEO,value);
				}
				return true;
			default:
				throw new BadDataException("Unknown column "+ident.col+" for row 419");
		}
		case 420:
			switch(ident.col){
			case 21:
				if ( ident.ctype==10){					
					parent.putFarmData(FBSFarmDatum.TOTALBYPRODUCTSAREA, value);
				}
				return true; // return true regardless
			case 26:
				if ( ident.ctype==10){					
					parent.putFarmData(FBSFarmDatum.TOTALBYPRODUCTSOPENV, value);
				}
				return true; // return true regardless
			case 28:
				if ( ident.ctype==10){					
					parent.putFarmData(FBSFarmDatum.TOTALBYPRODUCTSCLOSEV, value);
				}
				return true; // return true regardless
			case 30:
				if ( ident.ctype==10){					
					parent.putFarmData(FBSFarmDatum.TOTALBYPRODUCTSREVXSUBS, value);
				}
				return true; // return true regardless
			case 38:
				if ( ident.ctype==10){					
					parent.putFarmData(FBSFarmDatum.TOTALBYPRODUCTSFARMCONS, value);
				}
				return true; // return true regardless
			case 40:
				if ( ident.ctype==10){					
					parent.putFarmData(FBSFarmDatum.TOTALBYPRODUCTSSUBS, value);
				}
				return true; // return true regardless
			case 41:
				if ( ident.ctype==10){					
					parent.putFarmData(FBSFarmDatum.TOTALBYPRODUCTSEO, value);
				}
				return true; // return true regardless
			case 50:
				// Ignore
				return true;
			default:	
				throw new BadDataException("Unknown column "+ident.col+" for row 420");
			}
		}
		return false;
	}
	

	public static void addSectionAData(FBSFarmData parent,FBSPost2000DataPoint ident,double value) throws BadDataException {
		switch ( ident.row ){
		case 7:
			parent.putFarmData(FBSFarmDatum.FORMOFBUSINESS, value);
			break;
		case 33:
			parent.putFarmData(FBSFarmDatum.INCONSERVATIONSCHEME, value);
			break;
		case 3:
			parent.putFarmData(FBSFarmDatum.FARMID, value);
			break;
		case 1:
			parent.putFarmData(FBSFarmDatum.REGION, value);
			break;
		case 2:
			parent.putFarmData(FBSFarmDatum.COUNTY, value);
			break;
		case 11:
			parent.putFarmData(FBSFarmDatum.ALTITUDE, value);
			break;
		case 15:
			parent.putFarmData(FBSFarmDatum.TOTALMAINSETASIDE, value);
			break;
		case 16:
			parent.putFarmData(FBSFarmDatum.TOTALGRASS, value);
			break;
		case 17:
			parent.putFarmData(FBSFarmDatum.UTILIZEDAREA, value);
			break;
		case 39:
			parent.putFarmData(FBSFarmDatum.AREAELIGIBLEAAPS, value);
			break;
		case 68:
			parent.putFarmData(FBSFarmDatum.AREAELIGIBLESPS, value);
			break;
		}
	}
	
	public static void addSectionBData(FBSFarmData parent,FBSPost2000DataPoint ident,double value) throws BadDataException {
		switch ( ident.row ){
		case 18:
			switch( ident.col){
			case 5:
				parent.putFarmData(FBSFarmDatum.TOTALLABOURHOURS, value);
				break;
			case 6:
				parent.putFarmData(FBSFarmDatum.TOTALLABOURCOST, value);
				break;				
			}
			break;
		case 19:
			switch( ident.col){
			case 2:
				parent.putFarmData(FBSFarmDatum.FARMERDOB, value);
				break;
			case 8:
				parent.putFarmData(FBSFarmDatum.FARMEREC, value);
				break;
			case 5:
				parent.putFarmData(FBSFarmDatum.FARMERTIMEWORKED, value);
				break;
			}
			break;
		}
	}
	
}
